package com.bdqn.controller;

import com.bdqn.common.Page;
import com.bdqn.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@RequestMapping("/admin/account")
@Controller
public class AccountMapperController {
    @Autowired
    private AccountService accountService;
    /**
     * 分页查询客户信息
     *
     * @param name
     * @param page
     * @return
     */
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> list(@RequestParam(name = "name", defaultValue = "") String name,
                                    @RequestParam(name = "realName", defaultValue = "") String realName,
                                    @RequestParam(name = "idCard", defaultValue = "") String idCard,
                                    @RequestParam(name = "mobile", defaultValue = "") String mobile,
                                    @RequestParam(name = "status", required = false) Integer status, Page page) {
        Map<String, Object> ret = new HashMap<String, Object>();
        Map<String, Object> queryMap = new HashMap<String, Object>();
        queryMap.put("name", name);
        queryMap.put("status", status);
        queryMap.put("realName", realName);
        queryMap.put("idCard", idCard);
        queryMap.put("mobile", mobile);
        queryMap.put("offset", page.getOffset());
        queryMap.put("pageSize", page.getRows());
        ret.put("rows", accountService.findList(queryMap));
        ret.put("total", accountService.getTotal(queryMap));
        return ret;
    }
}
